package com.wuyan.locationdog.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.annotation.Nullable
import com.arcsoft.commonbase.bean.TeamMember
import com.arcsoft.commonbase.ext.ImageOptions
import com.arcsoft.commonbase.ext.gone
import com.arcsoft.commonbase.ext.loadImage
import com.arcsoft.commonbase.ext.visible
import com.wuyan.locationdog.R


class TeamGridView(context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int) :
    LinearLayout(context, attrs, defStyleAttr) {

    constructor(context: Context) : this(context, null)
    constructor(context: Context, @Nullable attrs: AttributeSet?) : this(context, attrs, 0)


    private val mInflater: LayoutInflater = LayoutInflater.from(getContext())

    init {
        val view: View = mInflater.inflate(R.layout.team_grid, this, true)
//        addView(view)
    }


    fun setTeamNum(teamMembers: List<TeamMember>) {
        val num = teamMembers.size
        val row1 = findViewById<View>(R.id.row1)
        val row2 = findViewById<View>(R.id.row2)
        val row3 = findViewById<View>(R.id.row3)

        val iv1 = findViewById<ImageView>(R.id.iv1)
        val iv2 = findViewById<ImageView>(R.id.iv2)
        val iv3 = findViewById<ImageView>(R.id.iv3)
        val iv4 = findViewById<ImageView>(R.id.iv4)
        val iv5 = findViewById<ImageView>(R.id.iv5)
        val iv6 = findViewById<ImageView>(R.id.iv6)
        val iv7 = findViewById<ImageView>(R.id.iv7)
        val iv8 = findViewById<ImageView>(R.id.iv8)
        val iv9 = findViewById<ImageView>(R.id.iv9)

        val list = mutableListOf<ImageView>()
        list.add(iv1)
        list.add(iv2)
        list.add(iv3)
        list.add(iv4)
        list.add(iv5)
        list.add(iv6)
        list.add(iv7)
        list.add(iv8)
        list.add(iv9)

        list.forEach {
            it.gone()
        }
        for (i in 0 until num) {
            list[i].visible()
            list[i].loadImage(teamMembers[i].userAvatar, ImageOptions().apply {
                placeholder = com.arcsoft.commonbase.R.mipmap.head
                error = com.arcsoft.commonbase.R.mipmap.head
                fallback = com.arcsoft.commonbase.R.mipmap.head
            })
        }


    }


}





